package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.base.exception.XueChengPlusException;
import com.xuecheng.content.mapper.CourseTeacherMapper;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 课程-教师关系表 服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class CourseTeacherServiceImpl extends ServiceImpl<CourseTeacherMapper, CourseTeacher> implements CourseTeacherService {

    @Override
    public List<CourseTeacher> getTeacherInfo(Long courseId) {

        return lambdaQuery().eq(CourseTeacher::getCourseId,courseId).list();
    }

    @Override
    public void saveOrUpdateTeacher(CourseTeacher courseTeacher) {

        //表单校验
        String teacherName = courseTeacher.getTeacherName();
        if (StringUtils.isEmpty(teacherName)){
            throw new XueChengPlusException("教师姓名不能为空");
        }

        String position = courseTeacher.getPosition();
        if (StringUtils.isEmpty(position)){
            throw new XueChengPlusException("教师职位不能为空");
        }

        if (courseTeacher.getId()==null){
            courseTeacher.setCreateDate(LocalDateTime.now());
        }
        saveOrUpdate(courseTeacher);



    }
}
